package com;

import com.pojo.Customer;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import util.MybatisUtils;

import java.util.ArrayList;
import java.util.List;

public class CustomerTest {
    @Test
    public void updateCustomerBysetTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        Customer customer = new Customer();
        customer.setId(3);
        customer.setPhone("186234567891");
        int rows = sqlSession.update("com.mapper.CustomerMapper.updateByPrimaryKey", customer);
        if (rows > 0) {
            System.out.println("您成功修改了" + rows + "条数据！");
        } else {
            System.out.println("执行修改操作失败！！！");
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void updateCustomerByTrimTest() {
        SqlSession sqlSession = MybatisUtils.getSession();
        Customer customer = new Customer();
        customer.setId(3);
        customer.setPhone("1331111111111");
        int rows = sqlSession.update("com.mapper.CustomerMapper.updateCustomByTrim", customer);
        if (rows > 0) {
            System.out.println("您成功修改了" + rows + "淘数据！");
        } else {
            System.out.println("执行修改操作失败！！！");
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void findByArrayTest(){
        SqlSession sqlSession = MybatisUtils.getSession();
        Integer [] roleIds = {2,3};
        List<Customer> customers = sqlSession.selectList("com.mapper.CustomerMapper.findByArray", roleIds);
        for (Customer customer : customers) {
            System.out.println(customer);
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void findByListTest(){
        SqlSession sqlSession = MybatisUtils.getSession();
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(2);
        List<Customer> customers = sqlSession.selectList("com.mapper.CustomerMapper.findByList",ids);
        for (Customer customer : customers) {
            System.out.println(customer);
        }
        sqlSession.commit();
        sqlSession.close();
    }
}